import { followOrUnfollow } from '@/services/consult'
import type { ContentType } from '@/types/consult'
import { ref } from 'vue'

export const useFollow = (type: ContentType = 'doc') => {
  const loading = ref(false)
  const follow = async (item: { likeFlag: 0 | 1; id: string }) => {
    loading.value = true
    try {
      await followOrUnfollow(type, item.id)
      item.likeFlag = item.likeFlag === 1 ? 0 : 1
    } finally {
      loading.value = false
    }
  }
  return { follow, loading }
}
